package org.example.JUC.Future;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @description:
 * @author: farprt
 * @create: 2022-09-09 20:35
 **/
public class BasicDemo {

    static class Task implements Callable<Integer>{

        @Override
        public Integer call() throws Exception {
            int sleepSeconds=new Random().nextInt(1000);
            Thread.sleep(sleepSeconds);
            return sleepSeconds;
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ExecutorService executor= Executors.newSingleThreadExecutor();
        Future<Integer> future=executor.submit(new Task());
        Thread.sleep(100);
        try {
            System.out.println(future.get());
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        executor.shutdown();
    }
}